package android.demo.broadcast;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.demo.BaseActivity;
import android.demo.R;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class DisplayActivity extends BaseActivity {

	private Notification n ;
	private NotificationManager nm;
	private static final int ID = 1;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        TextView tvDisplay = new TextView(this);
        tvDisplay.setText("显示通知界面");
        layout.addView(tvDisplay, params);
        
        Button btn = new Button(this);
        btn.setText("取消通知");
        btn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				nm.cancel(ID);
			}
		});
        layout.addView(btn);
        this.setContentView(layout, params);
        
        nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        n = new Notification();

        int icon = n.icon = R.drawable.happy; 
        String tickerText = "Test Notification"; 
        long when = System.currentTimeMillis();
        n.icon = icon;
        n.tickerText = tickerText;
        n.when = when;
        
        Intent intent = new Intent(this, BroadcastActivity.class); 
        PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); 
        n.setLatestEventInfo(this, "My Title", "My Content", pi);
        nm.notify(ID, n);
    }
}
